package com.wxy.zhuzhoubaoliao;

import java.util.List;

import com.ak.zhuzhou.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

class MyAdapter extends BaseAdapter{
	
	private List<Baoliao> list;
	private Context context;
	private LinearLayout.LayoutParams params;
	private LinearLayout.LayoutParams params2;
	
	public MyAdapter(List<Baoliao> list, Context context, LayoutParams params,
			LayoutParams params2) {
		super();
		this.list = list;
		this.context = context;
		this.params = params;
		this.params2 = params2;
	}

	class  ViewHolder{
		TextView title;
		ImageView picture1;
		ImageView picture2;
		ImageView picture3;
		TextView summary;
		TextView baoliaoren;
		TextView time;
		ImageView commentpicture;
		TextView commentcount;
	}
	
	@Override
	public View getView(int position, View convertView,
			ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder=new ViewHolder();
		Baoliao p=list.get(position);
		if(convertView==null){
			LayoutInflater inflater=LayoutInflater.from(context);
			convertView=inflater.inflate(R.layout.y_baoliao3item1, null);
			viewHolder.title=(TextView) convertView.findViewById(R.id.title);
			viewHolder.summary=(TextView) convertView.findViewById(R.id.summary);
			viewHolder.time=(TextView) convertView.findViewById(R.id.time);
			viewHolder.baoliaoren=(TextView) convertView.findViewById(R.id.baoliaoren);
			viewHolder.commentcount=(TextView) convertView.findViewById(R.id.commentcount);
			viewHolder.commentpicture=(ImageView) convertView.findViewById(R.id.commentpicture);
			viewHolder.picture1=(ImageView) convertView.findViewById(R.id.picture1);
			viewHolder.picture2=(ImageView) convertView.findViewById(R.id.picture2);
			viewHolder.picture3=(ImageView) convertView.findViewById(R.id.picture3);
			convertView.setTag(viewHolder);
		}
		else{
			viewHolder=(ViewHolder) convertView.getTag();
		}
		viewHolder.title.setText(p.getTitle());
		viewHolder.summary.setText(p.getSummary());
		viewHolder.time.setText(p.getTime());
		viewHolder.baoliaoren.setText(p.getBaoliaoren());
		viewHolder.commentcount.setText(p.getCommentcount());
		
		int [] images=p.getPictures();
		
		if(images.length==0){
			viewHolder.picture1.setLayoutParams(params);
			viewHolder.picture2.setLayoutParams(params);
			viewHolder.picture3.setLayoutParams(params);
		}
		else if(images.length==1){
			viewHolder.picture1.setLayoutParams(params2);
			viewHolder.picture1.setImageResource(images[0]);
			viewHolder.picture2.setLayoutParams(params);
			viewHolder.picture3.setLayoutParams(params);
		}
		else if(images.length==2){
			viewHolder.picture1.setLayoutParams(params2);
			viewHolder.picture2.setLayoutParams(params2);
			viewHolder.picture1.setImageResource(images[0]);
			viewHolder.picture2.setImageResource(images[1]);
			viewHolder.picture3.setLayoutParams(params);
		}
		else if(images.length==3){
			viewHolder.picture1.setLayoutParams(params2);
			viewHolder.picture2.setLayoutParams(params2);
			viewHolder.picture3.setLayoutParams(params2);
			viewHolder.picture1.setImageResource(images[0]);
			viewHolder.picture2.setImageResource(images[1]);
			viewHolder.picture3.setImageResource(images[2]);	
		}
		int img=p.getCommentpicture();
		
		viewHolder.commentpicture.setImageResource(img);
		
		return convertView;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
}